export class Water {
  constructor(temp: number) {
    this.temp = temp;
  }
  temp: number;
  get density() {
    return Water.getDensity(this.temp);
  }
  /** 根据水温获取水的密度。
   * 利用x、y坐标求出一元多项式 ,采用最小二乘法
   * @param temp 温度，单位：℃
   * @returns 水的密度，单位：Kg/m3
   */
  static getDensity = (temp: number) => {
    if (temp <= 0 || temp >= 100) {
      throw new Error("Argument out Of range exception,value range:0~100");
    }
    const x3 = 3.812451261359 * Math.pow(10, -5);
    const x2 = -0.0076329282535;
    const x1 = 0.05321983;
    const x0 = 999.9175848392126;
    const ys = x3 * temp * temp * temp + x2 * temp * temp + x1 * temp + x0;
    return ys;
  };

  /** 根据压力获取定压比热容。
   *
   * @param press 大气压压力，单位：几个大气压
   * @returns 定压比热容，kJ/（kg·℃）
   */
  static getHeatCapacity = (press: number = 1) => {
    if (press <= 0 || press >= 50) {
      throw new Error("Argument out Of range exception,value range:0~50");
    }
    return Constant.WaterCp - (press - 1) / 5000;
  };
}
